今天進度 鳥哥私房菜 - 第十五章、例行性工作排程(crontab)
我在 Crontab.guru - The cron schedule expression editor 練習 crontab 表達式
corntab 的規則如下:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
crontab -e
開啟編輯1 * * * * wall 'HI IT幫'
crontab -l
驗證是否有列入排程systemctl restart crond
重啟服務test@test:~$ crontab -e # 開啟編輯
*/1 * * * * wall 'HI IT幫' # 輸入保存
crontab: installing new crontab # 顯示正在安裝
test@test:~$ crontab -l # 顯示目前運行的
*/1 * * * * wall 'HI IT幫'
test@test:~$ systemctl restart crond
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'crond.service'.
Authenticating as: test
Password:
==== AUTHENTICATION COMPLETE ===
Failed to restart crond.service: Unit crond.service not found.
# 等一分鐘後
Broadcast message from test@test (somewhere) (Wed Oct 21 01:01:01 2020):
HI IT幫
@reboot touch 路徑
測試
test@test:~$ crontab -e
@reboot touch /home/test/start.txt
test@test:~$ reboot
test@test:~$ ls
start.txt
pwd
測試
test@test:~$ pwd
/home/test
我參考 Display the Path of Your Current Directory | Navigating Your File System in Linux | InformIT
一天一Linux,頭髮遠離我 ~